package com.itheima.mapper;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    //根据id查询用户
    @Select("select * from user where id = #{id}")
    User findById(Integer id);

    //查询所有用户及其所依赖其他信息
    @Select("select * from user")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            //配置与Orders的映射关系，根据user的id在orders表中查找对应的订单信息
            @Result(property = "ordersList",javaType = List.class,column ="id",
                    many = @Many(select = "com.itheima.mapper.OrdersMapper.findByUid")
            )
    })
    List<User> findAll();
}
